package JavaStructure.List.Crad;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CreatCard {

    public static List<Card> NewCard() {
        List<Card> DeckOfCards = new ArrayList<>();
        String[] suits = new String[]{"♠", "♥", "♦", "♣"};

        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                String suit = suits[i];
                int rank = j;
                Card card = new Card(j, suits[i]);

                DeckOfCards.add(card);
            }
        }
        return DeckOfCards;
    }

    public List<Card> Swap(List<Card> cards) {
        System.out.println("洗牌捏~");
        Random ran = new Random();
        for(int i = 0;i < cards.size() ; i++){
            int a = ran.nextInt(cards.size());
            Card tcard  = cards.get(i);
            cards.set(i,cards.get(a));
            cards.set(a, tcard);
        }
        return cards;
    }

    public void DealCard(List<Card> cards,int index) {
        Random ran = new Random();
        Card card = cards.remove(ran.nextInt(cards.size()));
        Card cardx = cards.get(ran.nextInt(cards.size()));

        List<List<Card>> Presons = new ArrayList<>(index);
        for (int i = 0; i < index; i++) {
            Presons.add(new ArrayList<>());
        }


//        List<Card> Preson2 = new ArrayList<>();
//        List<Card> Preson3 = new ArrayList<>();


        while (cards.size() > index){
            for(int j = 0 ; j < index ; j++){
                Card card1 = cards.remove(0);
                Presons.get(j).add(card1);
            }
        }

        System.out.println("发牌" );
        int k = 0;
        System.out.println("抽到" + card + "的是地主");
        System.out.println("地主牌：" + cardx.toString());
        while(index > k){
            System.out.println("牌友" + (k + 1) + "；" + "{" +Presons.get(k).toString() + "}");
            if(Presons.get(k).contains(card)){
                System.out.println("牌友" + (k + 1) +"抽到" + card + "是地主");
                Presons.get(k).add(cardx);
                System.out.println("牌友" + (k + 1) + "是地主" + "更新牌为" + Presons.get(k).toString());
            }
            k++;

        }


        System.out.println("剩下的牌：" + cards.toString());

        return;

    }



}
